import threading
import datetime

class clock(object):
    analogue_value = 0.0001
    timer = None
    enabled = True
    __now = None

    def run(self):
        self.timer = threading.Timer(0.1, self.tick)
        self.timer.start()

    def tick(self):
        self.__now = datetime.datetime.now()
        strTime = self.__now.strftime('%Y-%m-%d %H:%M:%S.%f')
        # print("当前时间为：" + strTime)
        self.analogue_value += 0.0001
        # print(self.analogue_value)
        if self.enabled == True:
            self.run()  # 重复设置定时器，以重复


myClock = clock()
myClock.run()
strCmd = input("请输入命令（s:sample, e:exit）：")
boolTerminated = False
while(boolTerminated == False):
    strCmd = input("请输入命令（ e:exit）：")
    if strCmd == 's':
        print(myClock.analogue_value)
    if strCmd == 'e':
        myClock.enabled = False
        boolTerminated = True
